package com.chanceit.ssss.activity;

import org.gl.GlobalVariable;
import org.gl.customview.ViewPager;
import org.gl.customview.viewpager.PagerSlidingTabStrip;

import android.content.Intent;
import android.os.Bundle;
import android.util.TypedValue;

import com.chanceit.ssss.adapters.CareCarTabPagerAdapter;
import com.chanceit.ssss.common.IntentExtraDataKey;
import com.chanceit.ssss.data.DataSources;

public class CareCarActivity extends BaseFragmentActivity {
	CareCarTabPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_business);
		mSectionsPagerAdapter = new CareCarTabPagerAdapter(
				getSupportFragmentManager(), this);

		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);
		int selectIndex = 0;
		if (DataSources.BusinessType_birthday.equals(getIntent()
				.getStringExtra(IntentExtraDataKey.BUSINESS_TYPE))) {
			selectIndex = mSectionsPagerAdapter.getCount() - 1;

		}
		if (selectIndex > mSectionsPagerAdapter.getCount() || selectIndex < 0) {
			selectIndex = 0;
		}
		mViewPager.setCurrentItem(selectIndex);
		final int pageMargin = (int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
						.getDisplayMetrics());
		mViewPager.setPageMargin(pageMargin);
		
		PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		if (tabs!=null) {
			tabs.setViewPager(mViewPager);
			tabs.setIndicatorColor(0xFF3F9FE0);
		}
		if (findViewById(R.id.fragment_container) != null) {
			if (savedInstanceState != null) {
				return;
			}
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
	}
	@Override
	public void onBackPressed() {
		GlobalVariable.getGlobalInstance().intent.putExtra(IntentExtraDataKey.BUSINESS_TYPE,"unknow");
		super.onBackPressed();
	}
}
